package com.kgc.manager.controller;

import com.kgc.entity.TbContent;
import com.kgc.manger.service.ContentService;
import com.kgc.utils.ItripResult;
import com.kgc.utils.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class ContentController {
    @Autowired
    private ContentService contentService;

    //显示所有内容
    @RequestMapping("content/list")
    @ResponseBody
    public ResultTable  contentList(
            @RequestParam(value = "page",required = false,defaultValue = "1") int page,
            @RequestParam(value = "limit",required = false,defaultValue = "5" ) int limit){

        return contentService.findAll(page,limit);
    }

    //增加一个内容
    @RequestMapping("content/add")
    @ResponseBody
    public ItripResult contentAdd(TbContent content){
        content.setUpdated(new Date());
        content.setCreated(new Date());
        return  contentService.addContent(content);
    }
}
